using System;
using System.Collections.Generic;
using System.Text;

namespace Eve.Data
{
    public class Attribute : EveProperty
    {
        private string attributeName;
        private int attributeCategory;
        private string description;
        private int maxAttributeId;
        private int attributeIndex;
        private int graphicId;
        private int chargeRechargeTimeId;
        private int defaultValue;
        private bool published;
        private string displayName;
        private int unitId;
        private bool stackable;
        private bool highIsGood;

        private Attribute maxAttribute;
        private Graphic graphic;
        private Unit unit;

        public string Name
        {
            get { return attributeName; }
        }
        public int Category
        {
            get { return attributeCategory; }
        }
        public string Description
        {
            get { return description; }
        }
        public Attribute Max
        {
            get
            {
                if (maxAttribute == null)
                    maxAttribute = new Attribute(db, maxAttributeId);
                return maxAttribute;
            }
        }
        public Graphic Graphic
        {
            get
            {
                if (graphic == null)
                    graphic = new Graphic(db, graphicId);
                return graphic;
            }
        }
        public int ChargeRechargeTimeId
        {
            get { return chargeRechargeTimeId; }
        }
        public int DefaultValue
        {
            get { return defaultValue; }
        }
        public bool Published
        {
            get { return published; }
        }
        public string DisplayName
        {
            get { return displayName; }
        }
        public Unit Unit
        {
            get
            {
                if (unit == null)
                    unit = new Unit(db, unitId);
                return unit;
            }
        }
        public bool Stackable
        {
            get { return stackable; }
        }
        public bool HighIsGood
        {
            get { return highIsGood; }
        }

        internal Attribute(DbDataRow dr)
            : base(dr.Database, EvePropertyType.Attribute, dr["attributeID"])
        {
            Fill(dr);
        }
        internal Attribute(Database db, int id)
            : base(db, EvePropertyType.Attribute, id)
        {
            Fill(db.ExecuteSingle("SELECT * FROM dgmAttributeTypes WHERE attributeID=" + id));
        }

        private void Fill(DbDataRow dr)
        {
            attributeName = dr["attributeName"];
            attributeCategory = dr["attributeCategory"];
            description = dr["description"];
            maxAttributeId = dr["maxAttributeID"];
            attributeIndex = dr["attributeIdx"];
            graphicId = dr["graphicID"];
            chargeRechargeTimeId = dr["chargeRechargeTimeID"];
            defaultValue = dr["defaultValue"];
            published = dr["published"];
            displayName = dr["displayName"];
            unitId = dr["unitID"];
            stackable = dr["stackable"];
            highIsGood = dr["highIsGood"];
        }
    }
}
